import java.util.*;

/**
 * @author LKQ
 * @date 2022/5/21 9:00
 * @description 利用迭代器支持的操作，next()和 hasNext()
 */
public class Solution {
    public static void main(String[] args) {

    }
    class PeekingIterator implements Iterator<Integer> {
        public Iterator<Integer> iterator;
        public Integer nextElement;
        public PeekingIterator(Iterator<Integer> iterator) {
            // initialize any member here.
            this.iterator = iterator;
            nextElement = iterator.next();
        }

        // Returns the next element in the iteration without advancing the iterator.
        public Integer peek() {
            return nextElement;
        }

        // hasNext() and next() should behave the same as in the Iterator interface.
        // Override them if needed.
        @Override
        public Integer next() {
            Integer ret = nextElement;
            nextElement = iterator.hasNext() ? iterator.next() : null;
            return ret;
        }

        @Override
        public boolean hasNext() {
            return nextElement != null;
        }
    }
}
